package com.stox.client.ui.javafx.chartingy.widget.menu;

import java.util.Iterator;

import javafx.scene.control.ContextMenu;
import javafx.scene.control.MenuItem;

import org.springframework.stereotype.Component;

import com.stox.client.core.model.intf.HasNavigable;
import com.stox.client.ui.javafx.chartingy.view.ChartingViewDisplayHelper;
import com.stox.client.ui.javafx.widget.ContextMenuConfigurer;

@Component
public class ChartingContextMenuConfigurer implements ContextMenuConfigurer {
	
	private ChartingViewDisplayHelper chartingViewDisplayHelper = new ChartingViewDisplayHelper();
	
	@Override
	public void clear(ContextMenu contextMenu) {
		if(null != contextMenu){
			Iterator<MenuItem> iterator = contextMenu.getItems().iterator();
			while(iterator.hasNext()){
				MenuItem menuItem = iterator.next();
				if(menuItem instanceof ChartingMenuItemMarker){
					iterator.remove();
				}
			}
		}
	}

	@Override
	public void configure(ContextMenu contextMenu) {
		if(!(contextMenu instanceof ChartingContextMenu) &&
				(contextMenu instanceof HasNavigable)){
			contextMenu.getItems().add(new SingleChartMenuItem(chartingViewDisplayHelper));
			contextMenu.getItems().add(new MultiChartMenuItem(chartingViewDisplayHelper));
		}
	}

}
